package com.gnerv.business.platform.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gnerv.business.platform.entity.DeptUser;
import com.gnerv.business.platform.entity.User;
import com.gnerv.business.platform.mapper.DeptUserMapper;
import com.gnerv.business.platform.mapper.UserMapper;
import com.gnerv.business.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gnerv
 * @since 2018-06-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    DeptUserMapper deptUserMapper;

    @Override
    public boolean updateByUserId(User user) {
        Integer i = userMapper.updateByUserId(user);
        return i == 1 ? true : false;
    }

    @Override
    public boolean createDeptUser(User user, String deptId) {
        Integer i1 = userMapper.insert(user);
        DeptUser deptUser = new DeptUser();
        deptUser.setDeptId(deptId);
        deptUser.setUserId(user.getUserId());
        Integer i2 = deptUserMapper.insert(deptUser);
        return i1 == 1 && i2 == 1 ? true : false;
    }

}
